// pages/shopList/shopList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shopList:[],
    pageIndex:0,
    pageSize:20,
    catId:1,
    hasMore:true
  },
  loadMore:function(){
      if(!this.data.hasMore){
          return;
      }
      wx.request({
          url: 'https://locally.uieee.com/categories/' + this.data.catId + '/shops',
          data: {
              _page: ++this.data.pageIndex,
              _limit: this.data.pageSize
          },
          success: (res) => {
              var newList=this.data.shopList.concat(res.data);
            //   获取数据的总数
              var count=parseInt(res.header['X-Total-Count']);
              var flag=this.data.pageIndex*this.data.pageSize<count
              this.setData({
                  shopList: newList,
                  hasMore:flag
              })
          }
      })
  },
  onLoad: function (options) {
    //   设置导航条标题
      wx.setNavigationBarTitle({
          title: options.title,
      })
      this.setData({
          catId: options.cat
      })
     this.loadMore()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    //   1.先把数据设置成默认值
        this.setData({
            shopList:[],
            pageIndex:0,
            hasMore:true
        })
        // 2、重新请求数据
        this.loadMore()
        wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      this.loadMore()
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})